<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SetWorkingDir</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>SetWorkingDir</h1>

<p>Changes the script's current working directory.</p>

<pre class="Syntax">SetWorkingDir, DirName</pre>
<h3>Parameters</h3>
<dl>

  <dt>DirName</dt>
  <dd><p>The name of the new working directory, which is assumed to be a subfolder of the current <a href="../Variables.htm#WorkingDir">%A_WorkingDir%</a> if an absolute path isn't specified.</p></dd>

</dl>

<h3>ErrorLevel</h3>
<p><span class="ver">[v1.1.04+]</span> This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<h3>Remarks</h3>
<p>The script's working directory is the default directory that is used to access files and folders when an absolute path has not been specified. In the following example, the file <em>My Filename.txt</em> is assumed to be in %A_WorkingDir%: <code><a href="FileAppend.htm">FileAppend</a>, A Line of Text, My Filename.txt</code>.</p>
<p>A script's initial working directory is determined by how it was launched. For example, if it was run via shortcut -- such as on the Start Menu -- its working directory is determined by the &quot;Start in&quot; field within the shortcut's properties.</p>
<p>To make a script unconditionally use its own folder as its working directory, make its first line the following:</p>
<pre>SetWorkingDir %A_ScriptDir%</pre>
<p>Once changed, the new working directory is instantly and globally in effect throughout the script. All interrupted, <a href="Pause.htm">paused</a>, and newly launched <a href="../misc/Threads.htm">threads</a> are affected, including <a href="SetTimer.htm">Timers</a>.</p>
<h3>Related</h3>
<p><a href="../Variables.htm#WorkingDir">%A_WorkingDir%</a>, <a href="../Variables.htm#ScriptDir">%A_ScriptDir%</a>, <a href="FileSelectFolder.htm">FileSelectFolder</a></p>
<h3>Example</h3>
<pre class="NoIndent">SetWorkingDir %A_ScriptDir%
SetWorkingDir, D:\My Folder\Temp</pre>

</body>
</html>
